package com.sphd.emanu.activity.topupmonth;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.sphd.emanu.R;
import com.sphd.emanu.activity.topup.TopUpTodayActivity;
import com.sphd.emanu.adapter.TopUpMonthdapter;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.mvp.MVPBaseActivity;
import com.sphd.emanu.pojo.DayDepositSale;
import com.sphd.emanu.pojo.MonthDepositSale;
import com.sphd.emanu.pojo.login.User;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 月充值金额的查看
 *
 * @Author Hu
 * @Time 2017/4/24 -- 17:47.
 * @Email 87683202@qq.com
 */
public class TopupmonthActivity extends MVPBaseActivity<TopupmonthContract.View, TopupmonthPresenter> implements TopupmonthContract.View {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.topup_month)
    TextView topupMonth;
    @BindView(R.id.layout_topup_month)
    LinearLayout layoutTopupMonth;
    @BindView(R.id.my_recycler)
    RecyclerView myRecycler;
    @BindView(R.id.my_swf)
    SwipeRefreshLayout mySwf;
    TopUpMonthdapter topUpMonthdapter;
    Intent intent;
    Bundle bundle;
    User user;
    int type = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_topupmonth);
        ButterKnife.bind(this);
        initView();
        initAdapter();
        initEvent();
    }

    private void initEvent() {
        toolbar.setNavigationOnClickListener(v -> finish());
        mySwf.setOnRefreshListener(() -> addData());
        myRecycler.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                DayDepositSale dayDepositSale = (DayDepositSale) adapter.getItem(position);
                bundle.putSerializable(Constant.DAY_DEPOSIT_SALE, dayDepositSale);
                intent.putExtras(bundle);
                intent.setClass(context, TopUpTodayActivity.class);
                startActivity(intent);
            }
        });
    }

    private void initAdapter() {
        setRefresh(mySwf);
        setRecy(myRecycler);
        topUpMonthdapter = new TopUpMonthdapter(R.layout.item_topup_month, new ArrayList<DayDepositSale>());
        topUpMonthdapter.setEmptyView(emptyView);
        myRecycler.setAdapter(topUpMonthdapter);

    }

    private void initView() {
        setTitleBar(toolbar, "本月充值");
        intent = getIntent();
        bundle = intent.getExtras();
        user = (User) bundle.getSerializable(Constant.USER_ENTITY);

        addData();
    }

    private void addData() {
        showProgressDialog();
        mPresenter.saleMonthDepositSum(user.getOid());
    }

    @Override
    public void recBean(MonthDepositSale monthDepositSale) {
        dissProgressDialog();
        topupMonth.setText("￥" + monthDepositSale.getMonthSum());
        topUpMonthdapter.setNewData(monthDepositSale.getList());

    }
}
